package com.chookss.home.search.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chookss.R;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.home.interview.InterviewDetailActivity;
import com.chookss.home.search.entity.SearchAllEntity;
import com.chookss.tools.Utils;

import java.util.List;

import io.reactivex.annotations.Nullable;

public class SearchInterviewAdapter extends BaseQuickAdapter<SearchAllEntity.InterviewBean.ListBean, BaseViewHolderEx> {
    private Context context;
    private int width, height;
    private String key;

    public SearchInterviewAdapter(int layoutResId, Context context, @Nullable List<SearchAllEntity.InterviewBean.ListBean> data) {
        super(layoutResId, data);
        this.context = context;

    }

    @Override
    protected void convert(BaseViewHolderEx helper, SearchAllEntity.InterviewBean.ListBean item) {
        TextView tvTiltle = helper.getView(R.id.tvSearchInterviewTitle);
        TextView tvSearchType = helper.getView(R.id.tvSearchInterviewType);
        TextView ivSearchInterview = helper.getView(R.id.ivSearchInterview);
        TextView tvSearchInterviewName = helper.getView(R.id.tvSearchInterviewName);
        tvTiltle.setText(Utils.matcherSearchTitle(context.getResources().getColor(R.color.main_color),item.getExamName(),key));
        tvSearchType.setText(item.getPostName());
        String examName = item.getExamName();
        if (examName != null && examName.length() > 1) {
            ivSearchInterview.setText(examName.substring(0, 2));
        }
        if (!Utils.isNull(item.getEmployeeNames())) {
            tvSearchInterviewName.setText("应聘者：");
            tvSearchInterviewName.append(Utils.matcherSearchTitle(context.getResources().getColor(R.color.main_color), item.getEmployeeNames(), key));
        } else {
            tvSearchInterviewName.setText("创建人：");
            tvSearchInterviewName.append(Utils.matcherSearchTitle(context.getResources().getColor(R.color.main_color), item.getCreateEmployeeName(), key));
        }
        helper.getItemView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, InterviewDetailActivity.class);
                intent.putExtra("examCode", item.getExamCode());
                intent.putExtra("examName", item.getExamName());
                intent.putExtra("qrCodeValid", item.getQrCodeValid());
                context. startActivity(intent);
            }
        });
    }

    public void setKey(String key){
        this.key=key;
    }
}
